Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GrapheneIntegration: Track operation name for tracing #2704

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

keithhackbarth
Copy link

It is helpful to have the operation's name if trying to track the individual performance of GraphQL transactions using Sentry. This PR implements the approach suggested in this article, as part of the GrapheneIntegration()

Note: I looked and wasn't initially sure how to write a good test for this and also wasn't sure if this PR is even a good idea in the first place. So leaving a light version here for feedback.

@keithhackbarth keithhackbarth changed the title Track operation name for tracing GrapheneIntegration: Track operation name for tracing Feb 5, 2024
@czyber
Copy link
Contributor

czyber commented Feb 21, 2024

Hi @keithhackbarth, i would love to see this change!
Mind if I look into writing tests for it on the weekend?

czyber added a commit to czyber/sentry-python that referenced this pull request Feb 24, 2024
… query getsentry#2704

This commit adds a missing test for the graphene integration, so that we can be sure that a transaction with the corresponding query name is captured.
… query getsentry#2704

This commit adds a missing test for the graphene integration, so that we can be sure that a transaction with the corresponding query name is captured.

--amend
@czyber
Copy link
Contributor

czyber commented Feb 24, 2024

Hey @keithhackbarth, i added a test and made a PR on your fork 😄

czyber added a commit to czyber/sentry-python that referenced this pull request Mar 8, 2024
… query getsentry#2704

This commit adds a missing test for the graphene integration, so that we can be sure that a transaction with the corresponding query name is captured.

--amend
Copy link
Member

@szokeasaurusrex szokeasaurusrex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution! This PR will require some changes before we can merge it; I have described these in an inline comment.

Comment on lines +56 to +57
with hub.start_transaction(op="graphql", name=kwargs.get("operation_name")):
result = old_graphql_sync(schema, source, *args, **kwargs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be starting a span here rather than a transaction, since Graphene is likely to be called by a web server's response handler, which would already have a transaction automatically started for it (we integrate with the popular web frameworks, like Flask, Django, etc). Creating a transaction within a transaction leads to undefined behavior; they cannot be nested, so we need a span, not a transaction here.

Since spans do not have a name, the operation name should be stored in the span's description instead.

Lastly, the op should be one of the values listed under the GraphQL category in the "Usage" column of this table.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants